require 'socket'

# 绑定本地ip和端口
local_socket = Socket.new(Socket::AF_INET,Socket::SOCK_STREAM)
local_addr = Socket.pack_sockaddr_in(4481,'127.0.0.1')

local_socket.bind local_addr

# 绑定全部的ip和端口
any_socket = Socket.new Socket::AF_INET,:STREAM
any_addr = Socket.pack_sockaddr_in(4482,'0.0.0.0')
any_socket.bind any_addr

# 绑定错误的ip和端口
error_socket = Socket.new :INET,:STREAM
error_addr = Socket.pack_sockaddr_in(4483,'192.168.1.1')
error_socket.bind error_addr
#Cannot assign requested address - bind(2) for 192.168.1.1:4483 (Errno::EADDRNOTAVAIL)